#include<bits/stdc++.h>
#define ll long long
#define pir pair<int,int>
using namespace std;
const int maxn=200005;
int t,n;
ll ans,a[maxn];

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n,ans=0;
        ll tot=0;
        for(int i=1;i<=n;i++) cin>>a[i],tot+=a[i];
        if(n==2){
            cout<<tot<<"\n";
            continue;
        }
        for(int i=0;i<1<<n;i++){
            ll res=0,lst[2]={0,0};
            for(int j=1;j<=n;j++){
                int c=(i>>j-1)&1;
                res+=a[j]==a[lst[c]]?a[j]:0;
                lst[c]=j;
            }
            ans=max(res,ans);
        }
        cout<<ans<<"\n";
    }
    return 0;
}